package com.qf.industy.controller;

import com.qf.dto.PageDto;
import com.qf.vo.PageResult;
import com.qf.vo.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.qf.industy.service.IndustryService;
import com.qf.industy.entity.Industry;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 行业表 前端控制器
 * </p>
 *
 * @author
 * @since 2023-10-30
 */
@RestController
@CrossOrigin
@RequestMapping("/industry")
public class IndustryController {

    @Autowired
    private IndustryService industryService;

    @PostMapping("page")
    public PageResult<Industry> page(@RequestBody PageDto<Industry> pageDto){
        return industryService.pageInfo(pageDto);
    }

    /*添加和修改*/
    @PostMapping("add")
    public Result add(@RequestBody Industry industry){
        if (StringUtils.isEmpty(industry.getId())){
            return industryService.add(industry);
        }else{
            if(industryService.updateById(industry)){
                return new Result(0,"更新成功！");
            }else{
                return new Result(1,"更新失败！");
            }
        }
    }
}
